﻿using System;
using System.Globalization;
using DBAccessLibrary.Common;

namespace BaseControlLibrary
{
    public class BaseXmlHelper : ChDescriptionXml
    {

        public string FontName
        {
            get { return GetElement("FontName"); }
            set
            {
                SetElement("FontName", value);
                if(FontNameChange != null)
                    FontNameChange(value);
            }
        }
        public string FontSize
        {
            get { return GetElement("FontSize"); }
            set
            {
                SetElement("FontSize", value);
                if(FontSizeChange!=null)
                    FontSizeChange(Convert.ToDouble(value));
            }
        }
        /// <summary>
        /// 是否折叠代码
        /// </summary>
        public bool IsFloding
        {
            get
            {
                string value = GetElement("IsFloding");
                return !string.IsNullOrEmpty(value) && Convert.ToBoolean(value);
            }
            set
            {
                SetElement("IsFloding", value.ToString());
                if(FoldingChange!=null)
                    FoldingChange(value);
            }
        }

        /// <summary>
        /// 当是分页绑定时  则为分页数 ，否则 则是到达此记录数  提醒
        /// </summary>
        public decimal SelectMaxCount
        {
            get { 
                string value = GetElement("SelectMaxCount");
                if(string.IsNullOrEmpty(value))
                {
                    return 10*10000;
                }
                decimal count;
                decimal.TryParse(value, out count);
                if (count == 0)
                    return 10*10000;
                return count;
            }
            set
            {
                SetElement("SelectMaxCount", value.ToString(CultureInfo.InvariantCulture));
            }
        }

        /// <summary>
        /// 界面展现方式 是否精简版本
        /// </summary>
        public bool IsSimpleControl
        {
            
            get {
                string value = GetElement("IsSimpleControl");
                if(string.IsNullOrEmpty(value))
                {
                    return false;
                }
                bool simple;
                bool.TryParse(value, out simple);
                return simple;
            }
            set
            {
                SetElement("IsSimpleControl", value.ToString(CultureInfo.InvariantCulture));
            }
        }

        /// <summary>
        /// 查询绑定方式 是否分页绑定
        /// </summary>
        public bool IsPageBind
        {
            get
            {
                string value = GetElement("IsPageBind");
                if (string.IsNullOrEmpty(value))
                {
                    return false;
                }
                bool simple;
                bool.TryParse(value, out simple);
                return simple;
            }
            set
            {
                SetElement("IsPageBind", value.ToString(CultureInfo.InvariantCulture));
            }
        }

        public Action<string> FontNameChange { get; set; }
        public Action<double> FontSizeChange { get; set; }
        public Action<bool> FoldingChange { get; set; }
    }
}
